home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 September (Japanese) / CICA Shareware for Windows CD-ROM (Walnut Creek) (September 1995) (Japanese) (Disc 2).iso / disc2 / winword / default.dir / text0000.txt < prev   
Encoding:
Text File  |  1992-04-13  |  4.1 KB  |  84 lines

  1.  
  2. I've seen a lot of discussion in recent weeks about how to get Microsoft
  3. Word for Windows to remember the last directory you were in from session
  4. to session.  While there are a number of somewhat kludgy ways to do this,
  5. I offer the following programatic solution. It's what I use every day and
  6. it works without fail.  Hopefully someone else out there in netland can
  7. make some good use of it.
  8.  
  9. There are three routines that probably do not already exist in your version
  10. of Word for Windows, but they are recognized.  All you have to do is add
  11. the code shown below to macros with the names shown just above Sub MAIN for
  12. each case..
  13.  
  14. The key to this whole scheme is the API call into Windows used by the
  15. AutoExit macro.  This is what writes the WIN.INI entry that can be retrieved
  16. when Word for Windows is next started.
  17.  
  18. Enjoy!
  19.  
  20. -------------------------Code Begins Here-----------------------------------
  21. AutoeExec
  22. Sub MAIN
  23.   ' This procedure checks attempts to return to the last directory used by
  24.   ' Microsoft Word for Windows. It checks the WIN.INI file for a
  25.   ' DefaultDirectory entry and changes to the directory path found there.
  26.   ' No action is taken if no entry exists
  27.  
  28.   AName$ = "Microsoft Word"                   ' Set Application Name.
  29.   KName$ = "DefaultDirectory"                 ' Set Key name.
  30.   NewDir$ = GetProfileString$(AName$, KName$) ' Get the last directory used.
  31.   ChDir NewDir$                               ' Change directory.
  32. End Sub
  33.  
  34. AutoOpen
  35. Sub MAIN
  36.   ' This procedure determines the path of the file that was just opened.
  37.   ' It then causes Word for Windows to make that directory the current
  38.   ' default directory for future FileOpen operations.
  39.  
  40.   Path$ = ""                              ' Initialize Path$.
  41.   LastFile$ = FileName$(1)                ' Get path of last file opened.
  42.   I = Len(LastFile$)                      ' Get length of filespec.
  43.   While Path$ = ""
  44.     If Mid$(LastFile$, I, 1) = "\" Then   ' Starting from the right,
  45.       Path$ = Left$(LastFile$, I - 1)     ' look for the last directory
  46.     End If                                ' delimiter (\). Take everything
  47.                                           ' to the left of the delimiter
  48.                                           ' for the path.
  49.     I = I - 1
  50.   Wend
  51.   ChDir Path$                             ' Change directory
  52. End Sub
  53.  
  54. AutoExit
  55. 'WIN API procedure to write a WIN.INI entry.
  56. Declare Function WriteProfileString Lib "Kernel"(AName$, KName$, Repl$) As Integer
  57.  
  58. Sub MAIN
  59.   ' This procedure determines the directory path of the last file opened.
  60.   ' It then writes the path to the DefaultDirectory entry in the WIN.INI.
  61.  
  62.   AName$ = "Microsoft Word"                ' Set Application Name.
  63.   KName$ = "DefaultDirectory"              ' Set Key Name.
  64.   Repl$ = ""                               ' Initialize replacement string.
  65.   LastFile$ = FileName$(1)                 ' Get path of last file opened.
  66.   I = Len(LastFile$)                       ' Get length of filespec.
  67.   While Repl$ = ""
  68.     If Mid$(LastFile$, I, 1) = "\" Then    ' Starting from the right,
  69.       Repl$ = Left$(LastFile$, I - 1)      ' look for the last directory
  70.     End If                                 ' delimiter (\). Take everything
  71.                                            ' to the left of the delimiter
  72.                                            ' for the path.
  73.     I = I - 1
  74.   Wend
  75.   X = WriteProfileString(AName$, KName$, Repl$)   ' Write to WIN.INI file.
  76. End Sub
  77. ---------------------------Code Ends Here-----------------------------------
  78.  
  79. -- 
  80. Frederick F. Freeland Jr.                        "Of all the things I've lost,  Microsoft Corporation                               I miss my mind the most!"   One Microsoft Way  
  81. Redmond, WA 98052 (206) 882-8080                                                                                                                                internet: fredf@microsoft.beaver.washington.EDU                                 arpanet:  fredf%microsoft@uw-beaver.ARPA
  82. uucp:     uunet!microsoft!fredf                                                                                                                                 Opinions expressed over this signature are my OWN and not those of my employer! 
  83.  
  84.